package com.bgs.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bgs.common.R;
import com.bgs.pojo.CustomerAddr;
import com.bgs.mapper.CustomerAddrMapper;
import com.bgs.service.CustomerAddrService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 地址表 服务实现类
 * </p>
 *
 * @author Asia
 * @since 2021-09-14
 */
@Service
public class CustomerAddrServiceImpl extends ServiceImpl<CustomerAddrMapper, CustomerAddr> implements CustomerAddrService {
    @Resource
    private CustomerAddrMapper customerAddrMapper;
    //添加用户地址
    @Override
    public R TowAddAddress(Map map) {
        LinkedHashMap addressData = (LinkedHashMap) map.get("addressData");
        Integer beforeUserId = Integer.parseInt(addressData.get("beforeUserId").toString());
        String address = new StringBuilder(addressData.get("selector").toString()).append("-").append(addressData.get("address")).toString();
        addressData.put("address",address);
        int i = customerAddrMapper.TowAddAddress(beforeUserId,addressData);
        return R.ok().data("i",i);
    }

    /**
     * 修改用户地址
     * @param map
     * @return
     */
    @Override
    public R TowUpdateAddress(Map map) {
        LinkedHashMap addressData = (LinkedHashMap) map.get("addressData");
        Integer beforeUserId = Integer.parseInt(addressData.get("beforeUserId").toString());
        String address = new StringBuilder(addressData.get("selector").toString()).append("-").append(addressData.get("address")).toString();
        addressData.put("addressData",address);
        int i = customerAddrMapper.TowUpdateAddress(beforeUserId,addressData);
        return R.ok().data("i",i);
    }

    @Override
    public R TowListAdd(Integer beforeUserId) {
        List<CustomerAddr> list = customerAddrMapper.TowListAdd(beforeUserId);
        return R.ok().data("list",list);
    }


}
